<template>
  <div id="user-modify">
    <h2 style="text-align: center;">修改设备信息-->{{form.gdId}}</h2>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="工地名称">
        <el-input v-model="form.gdName" placeholder="不可以为空"></el-input>
      </el-form-item>

		<el-form-item label="工地位置">
		  <el-input v-model="form.gdAddr" placeholder="可以为空"></el-input>
		</el-form-item>

		<el-form-item label="工地描述">
		  <el-input v-model="form.gdInfo" placeholder="可以为空"></el-input>
		</el-form-item>

      <el-form-item>
        <el-button type="primary" @click="modifysb()">修改</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

  export default{
    data(){
      return {
        form: {
		  gdId: '',
          gdName: '',
          gdAddr: '',
          gdInfo: ''
        }
      }
    },
    mounted() {
      var obj = this;
      this.axios({
        method:"get",
        url:"http://localhost:8088/gd/getGdById?id="+this.$route.params.id
      }).then(function(response){
        console.log(response.data)
        obj.form = response.data;
      })
    },
    methods:{
      modifysb() {
        var obj = this;
        this.axios({
          method:"POST",
          url:"http://localhost:8088/gd/update",
          data:obj.form
        }).then(function(response){
          var result = response.data;
          if (result.code==1000) {

            // 成功消息提示
            obj.$message({
              message: '恭喜你，修改成功',
              type: 'success'
            });

            // 延时跳转
            setTimeout(function(){
              obj.$router.push("/gds/gd")
            },2000)


          } else{
            obj.$message.error('错了哦，修改失败');
          }
        })
      }
    }
  }

</script>

<style>
  #user-modify{
    width: 400px;
    margin: auto;
  }
</style>
